import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tencent_cloud_chat_uikit/business_logic/view_models/tui_chat_global_model.dart';
import 'package:tencent_cloud_chat_uikit/ui/controller/tim_uikit_chat_controller.dart';
import 'package:yqmssa_app/config/app_config.dart';
import 'package:yqmssa_app/utils/shared_utils.dart';
import 'package:yqmssa_app/utils/tencent_im_utils.dart';
import 'package:yqmssa_app/views/landing/apply_request.dart';

class HumanCustomerManager extends GetxController {
  final data = CreateApplyDataModel().obs;

  getData() {
    data.value = sharedUtils.service!;
    if (AppConfig.appInitData.havePop == 1) {
      Future.delayed(const Duration(seconds: 1), tencentImUtils.inviteDialog);
    }
  }

  final controller = TIMUIKitChatController();

  @override
  void onInit() {
    super.onInit();
    getData();
  }

  void sendText() {
    if ((controller.textFieldController?.textEditingController?.text ?? "").isEmpty) return;
    controller.model
        ?.sendTextMessage(text: controller.textFieldController?.textEditingController?.text ?? "", convID: data.value.serviceTencentId, convType: ConvType.c2c)
        .then((onValue) {
      if ((onValue?.code ?? 0) == 0) {
        controller.textFieldController?.textEditingController?.clear();
        FocusScope.of(Get.context!).unfocus();
      }
    });
  }
}
